package com.asset.dispoal.evidenceconfig;

import com.asset.dispoal.evidenceconfig.api.BsEvidenceConfItemDetailService;
import com.asset.dispoal.evidenceconfig.dto.request.BsEvidenceConfItemDetailRequest;
import com.asset.dispoal.evidenceconfig.dto.response.BsEvidenceConfItemDetailResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.controller.BaseController;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;
import java.util.Map;

/**
 * @author qr
 * @date 2021/10/21$
 */
@RestController
@Api(value = "证据项配置", tags = "证据项配置")
@RequestMapping("/bs/evidenceConfItemDetail")
public class BsEvidenceConfItemDetailController extends BaseController {

    @Autowired
    private BsEvidenceConfItemDetailService bsEvidenceConfItemDetailService;


    @ApiOperation(value = "通用查询（分页）")
    @ApiImplicitParam(name = "bsEvidenceConfItemDetailRequest", value = "案件证据请求对象")
    @PostMapping("/queryByConfId")
    public Result<PageVO<BsEvidenceConfItemDetailResponse>> queryByConfId(@RequestBody BsEvidenceConfItemDetailRequest bsEvidenceConfItemDetailRequest) {
        final PageVO<BsEvidenceConfItemDetailResponse> listPageVO = bsEvidenceConfItemDetailService.queryPage(bsEvidenceConfItemDetailRequest);
        return Result.ok(listPageVO);
    }

    @ApiOperation(value = "修改/添加")
    @ApiImplicitParam(name = "BsEvidenceConfItemDetailRequest", value = "案件证据请求对象")
    @PostMapping("/insertOrUpdate")
    public Result insertOrUpdate(@RequestBody List<BsEvidenceConfItemDetailRequest> BsEvidenceConfItemDetailRequest) {
        bsEvidenceConfItemDetailService.batchInsertOrUpdate(BsEvidenceConfItemDetailRequest);

        return Result.ok();
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "BsEvidenceConfItemDetailRequest", value = "证据分类请求对象")
    @PostMapping("/del")
    public Result del(@RequestBody BsEvidenceConfItemDetailRequest BsEvidenceConfItemDetailRequest) {
        bsEvidenceConfItemDetailService.delete(BsEvidenceConfItemDetailRequest.getId());
        return Result.ok();
    }

    @ApiOperation(value = "获取证据分类映射列表")
    @ApiImplicitParam(name = "batchId", value = "批次id")
    @GetMapping("/findMapper")
    public Result findMapper(@RequestParam("batchId") String batchId) {
        final List<Map<String, String>> mapper = bsEvidenceConfItemDetailService.findMapper(batchId);
        return Result.ok(mapper);
    }

}
